package com.ld.rightsSystem.aop;

import com.ld.rightsSystem.Enum.ResponseEnum;
import com.ld.rightsSystem.exception.DBDataNotFoundException;
import com.ld.rightsSystem.vo.R;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.JwtException;
import org.postgresql.util.PSQLException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

@RestControllerAdvice(basePackages = {"com.ld.rightsSystem.controller"})
public class ControllerAdviser {
    /**
     * token过期
     * @return
     */
    @ExceptionHandler(JwtException.class)
    public R expiredJwtException(Exception e){
        e.printStackTrace();
        return new R().error(ResponseEnum.UNAUTHORIZED,null);
    }

    @ExceptionHandler(DBDataNotFoundException.class)
    public R dbDataNotFoundException(Exception e){
        e.printStackTrace();
        return new R().error(ResponseEnum.DB_DATA_NOT_FOUND,null);
    }

    @ExceptionHandler(SQLException.class)
    public R psqlxceptionHandler(Exception e){
        e.printStackTrace();
        return new R().error(ResponseEnum.DB_SAVE_ERROR,null);
    }

    @ExceptionHandler(Exception.class)
    public R exceptionHandler(Exception e){
        e.printStackTrace();
        return new R().error(ResponseEnum.ERROR,null);
    }
}
